home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qpainter.h.z / qpainter.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  15.5 KB  |  567 lines

  1. /****************************************************************************
  2. ** $Id: qpainter.h,v 2.27 1998/07/03 00:09:36 hanord Exp $
  3. **
  4. ** Definition of QPainter class
  5. **
  6. ** Created : 940112
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QPAINTER_H
  25. #define QPAINTER_H
  26.  
  27.  
  28. #ifndef QT_H
  29. #include "qpaintdevice.h"
  30. #include "qcolor.h"
  31. #include "qfontmetrics.h"
  32. #include "qfontinfo.h"
  33. #include "qregion.h"
  34. #include "qpen.h"
  35. #include "qbrush.h"
  36. #include "qpointarray.h"
  37. #include "qwmatrix.h"
  38. #endif // QT_H
  39.  
  40.  
  41. enum BGMode                    // background mode
  42.     { TransparentMode, OpaqueMode };
  43.  
  44. enum PaintUnit                    // paint unit
  45.     { PixelUnit, LoMetricUnit, HiMetricUnit, LoEnglishUnit, HiEnglishUnit,
  46.       TwipsUnit };
  47.  
  48.  
  49. #if defined(_WS_WIN_)
  50. struct QWinFont;
  51. #endif
  52.  
  53.  
  54. class QPainter                    // painter class
  55. {
  56. public:
  57.     QPainter();
  58.     QPainter( const QPaintDevice * );
  59.     QPainter( const QPaintDevice *, const QWidget * );
  60.    ~QPainter();
  61.  
  62.     bool    begin( const QPaintDevice * );
  63.     bool    begin( const QPaintDevice *, const QWidget * );
  64.     bool    end();
  65.     QPaintDevice *device() const;
  66.  
  67.     static void redirect( QPaintDevice *pdev, QPaintDevice *replacement );
  68.  
  69.     bool    isActive() const;
  70.  
  71.     void    flush();
  72.     void    save();
  73.     void    restore();
  74.  
  75.   // Drawing tools
  76.  
  77.     QFontMetrics fontMetrics()    const;
  78.     QFontInfo     fontInfo()    const;
  79.  
  80.     const QFont &font()        const;
  81.     void    setFont( const QFont & );
  82.     const QPen &pen()        const;
  83.     void    setPen( const QPen & );
  84.     void    setPen( PenStyle );
  85.     void    setPen( const QColor & );
  86.     const QBrush &brush()    const;
  87.     void    setBrush( const QBrush & );
  88.     void    setBrush( BrushStyle );
  89.     void    setBrush( const QColor & );
  90.  
  91.   // Drawing attributes/modes
  92.  
  93.     const QColor &backgroundColor() const;
  94.     void    setBackgroundColor( const QColor & );
  95.     BGMode    backgroundMode() const;
  96.     void    setBackgroundMode( BGMode );
  97.     RasterOp    rasterOp()    const;
  98.     void    setRasterOp( RasterOp );
  99.     const QPoint &brushOrigin() const;
  100.     void    setBrushOrigin( int x, int y );
  101.     void    setBrushOrigin( const QPoint & );
  102.  
  103.   // Scaling and transformations
  104.  
  105. //    PaintUnit unit()           const;        // get set painter unit
  106. //    void    setUnit( PaintUnit );        // NOT IMPLEMENTED!!!
  107.  
  108.     void    setViewXForm( bool );        // set xform on/off
  109.     bool    hasViewXForm() const;
  110.     QRect    window()       const;        // get window
  111.     void    setWindow( const QRect & );    // set window
  112.     void    setWindow( int x, int y, int w, int h );
  113.     QRect    viewport()   const;        // get viewport
  114.     void    setViewport( const QRect & );    // set viewport
  115.     void    setViewport( int x, int y, int w, int h );
  116.  
  117.     void    setWorldXForm( bool );        // set world xform on/off
  118.     bool    hasWorldXForm() const;
  119.     const QWMatrix &worldMatrix() const;    // get/set world xform matrix
  120.     void    setWorldMatrix( const QWMatrix &, bool combine=FALSE );
  121.  
  122.     void    translate( float dx, float dy );
  123.     void    scale( float sx, float sy );
  124.     void    shear( float sh, float sv );
  125.     void    rotate( float a );
  126.     void    resetXForm();
  127.  
  128.     QPoint    xForm( const QPoint & ) const;    // map virtual -> device
  129.     QRect    xForm( const QRect & )    const;
  130.     QPointArray xForm( const QPointArray & ) const;
  131.     QPointArray xForm( const QPointArray &, int index, int npoints ) const;
  132.     QPoint    xFormDev( const QPoint & ) const; // map device -> virtual
  133.     QRect    xFormDev( const QRect & )  const;
  134.     QPointArray xFormDev( const QPointArray & ) const;
  135.     QPointArray xFormDev( const QPointArray &, int index, int npoints ) const;
  136.  
  137.   // Clipping
  138.  
  139.     void    setClipping( bool );        // set clipping on/off
  140.     bool    hasClipping() const;
  141.     const QRegion &clipRegion() const;
  142.     void    setClipRect( const QRect & );    // set clip rectangle
  143.     void    setClipRect( int x, int y, int w, int h );
  144.     void    setClipRegion( const QRegion &);// set clip region
  145.  
  146.   // Graphics drawing functions
  147.  
  148.     void    drawPoint( int x, int y );
  149.     void    drawPoint( const QPoint & );
  150.     void    drawPoints( const QPointArray& a,
  151.                 int index=0, int npoints=-1 );
  152.     void    moveTo( int x, int y );
  153.     void    moveTo( const QPoint & );
  154.     void    lineTo( int x, int y );
  155.     void    lineTo( const QPoint & );
  156.     void    drawLine( int x1, int y1, int x2, int y2 );
  157.     void    drawLine( const QPoint &, const QPoint & );
  158.     void    drawRect( int x, int y, int w, int h );
  159.     void    drawRect( const QRect & );
  160.     void    drawWinFocusRect( int x, int y, int w, int h );
  161.     void    drawWinFocusRect( int x, int y, int w, int h,
  162.                   const QColor &bgColor );
  163.     void    drawWinFocusRect( const QRect & );
  164.     void    drawWinFocusRect( const QRect &,
  165.                   const QColor &bgColor );
  166.     void    drawRoundRect( int x, int y, int w, int h, int, int );
  167.     void    drawRoundRect( const QRect &, int, int );
  168.     void    drawEllipse( int x, int y, int w, int h );
  169.     void    drawEllipse( const QRect & );
  170.     void    drawArc( int x, int y, int w, int h, int a, int alen );
  171.     void    drawArc( const QRect &, int a, int alen );
  172.     void    drawPie( int x, int y, int w, int h, int a, int alen );
  173.     void    drawPie( const QRect &, int a, int alen );
  174.     void    drawChord( int x, int y, int w, int h, int a, int alen );
  175.     void    drawChord( const QRect &, int a, int alen );
  176.     void    drawLineSegments( const QPointArray &,
  177.                   int index=0, int nlines=-1 );
  178.     void    drawPolyline( const QPointArray &,
  179.                   int index=0, int npoints=-1 );
  180.     void    drawPolygon( const QPointArray &, bool winding=FALSE,
  181.                  int index=0, int npoints=-1 );
  182.     void    drawQuadBezier( const QPointArray &, int index=0 );
  183.     void    drawPixmap( int x, int y, const QPixmap &,
  184.                 int sx=0, int sy=0, int sw=-1, int sh=-1 );
  185.     void    drawPixmap( const QPoint &, const QPixmap &,
  186.                 const QRect &sr );
  187.     void    drawPixmap( const QPoint &, const QPixmap & );
  188.     void    drawImage( int x, int y, const QImage &,
  189.                int sx=0, int sy=0, int sw=-1, int sh=-1 );
  190.     void    drawImage( const QPoint &, const QImage &,
  191.                const QRect &sr );
  192.     void    drawImage( const QPoint &, const QImage & );
  193.     void    drawTiledPixmap( int x, int y, int w, int h, const QPixmap &,
  194.                  int sx=0, int sy=0 );
  195.     void    drawTiledPixmap( const QRect &, const QPixmap &,
  196.                  const QPoint & );
  197.     void    drawTiledPixmap( const QRect &, const QPixmap & );
  198.     void    drawPicture( const QPicture & );
  199.  
  200.     void    fillRect( int x, int y, int w, int h, const QBrush & );
  201.     void    fillRect( const QRect &, const QBrush & );
  202.     void    eraseRect( int x, int y, int w, int h );
  203.     void    eraseRect( const QRect & );
  204.  
  205.   // Text drawing functions
  206.  
  207.     void    drawText( int x, int y, const char *str, int len = -1 );
  208.     void    drawText( const QPoint &, const char *str, int len = -1 );
  209.     void    drawText( int x, int y, int w, int h, int flags,
  210.               const char *str, int len = -1, QRect *br=0,
  211.               char **internal=0 );
  212.     void    drawText( const QRect &, int flags,
  213.               const char *str, int len = -1, QRect *br=0,
  214.               char **internal=0 );
  215.  
  216.   // Text drawing functions
  217.  
  218.     QRect    boundingRect( int x, int y, int w, int h, int flags,
  219.                   const char *str, int len = -1, char **intern=0 );
  220.     QRect    boundingRect( const QRect &, int flags,
  221.                   const char *str, int len = -1, char **intern=0 );
  222.  
  223.     int        tabStops() const;
  224.     void    setTabStops( int );
  225.     int           *tabArray() const;
  226.     void    setTabArray( int * );
  227.  
  228.     HANDLE    handle() const;
  229.  
  230.     static void initialize();
  231.     static void cleanup();
  232.  
  233. private:
  234.     void    init();
  235.     void    updateFont();
  236.     void    updatePen();
  237.     void    updateBrush();
  238.     void    updateXForm();
  239.     void    updateInvXForm();
  240.     void    map( int, int, int *rx, int *ry ) const;
  241.     void    map( int, int, int, int, int *, int *, int *, int * ) const;
  242.     void    mapInv( int, int, int *, int * ) const;
  243.     void    mapInv( int, int, int, int, int *, int *, int *, int * ) const;
  244.     void    drawPolyInternal( const QPointArray &, bool close=TRUE );
  245.     void    drawWinFocusRect( int x, int y, int w, int h, bool xorPaint,
  246.                   const QColor &penColor );
  247.  
  248.     enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08,
  249.        VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100,
  250.        DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800,
  251.        RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000 };
  252.     ushort    flags;
  253.     bool    testf( ushort b ) const { return (flags&b)!=0; }
  254.     void    setf( ushort b )    { flags |= b; }
  255.     void    setf( ushort b, bool v );
  256.     void    clearf( ushort b )    { flags &= (ushort)(~b); }
  257.     void    fix_neg_rect( int *x, int *y, int *w, int *h );
  258.  
  259.     QPaintDevice *pdev;
  260.     QColor    bg_col;
  261.     uchar    bg_mode;
  262.     uchar    rop;
  263.     uchar    pu;
  264.     QPoint    bro;
  265.     QFont    cfont;
  266.     QPen    cpen;
  267.     QBrush    cbrush;
  268.     QRegion    crgn;
  269.     int        tabstops;
  270.     int           *tabarray;
  271.     int        tabarraylen;
  272.     QCOORD    wx, wy, ww, wh;
  273.     QCOORD    vx, vy, vw, vh;
  274.     QWMatrix    wxmat;
  275.     int        wm11, wm12, wm21, wm22, wdx, wdy;
  276.     int        im11, im12, im21, im22, idx, idy;
  277.     int        txop;
  278.     bool    txinv;
  279.     void       *penRef;                // pen cache ref
  280.     void       *brushRef;            // brush cache ref
  281.     void       *ps_stack;
  282.     void    killPStack();
  283.  
  284. protected:
  285. #if defined(_WS_WIN_)
  286.     HDC        hdc;                // device context
  287.     HANDLE    hpen;                // current pen
  288.     HANDLE    hbrush;                // current brush
  289.     HANDLE    hbrushbm;            // current brush bitmap
  290.     HANDLE    holdpal;
  291.     uint    pixmapBrush    : 1;
  292.     uint    nocolBrush    : 1;
  293.     QWinFont   *winFont;
  294.     void       *textMetric();
  295.     void    nativeXForm( bool );
  296. #elif defined(_WS_PM_)
  297.     HPS        hps;                // presentation space
  298.     int        dh;                // device height
  299.     long    lctrl;                // outline/fill control
  300.     void    updateCtrl();            // update lctrl
  301. #elif defined(_WS_X11_)
  302.     Display    *dpy;                // current display
  303.     WId        hd;                // handle to drawable
  304.     GC        gc;                // graphics context (standard)
  305.     GC        gc_brush;            // graphics contect for brush
  306.     QPoint    curPt;                // current point
  307. #endif
  308.     friend class QFontMetrics;
  309.     friend class QFontInfo;
  310.     friend void qt_format_text( const QFontMetrics& fm, int x, int y, int w, int h,
  311.              int tf, const char *str, int len, QRect *brect,
  312.              int tabstops, int* tabarray, int tabarraylen,
  313.              char **internal, QPainter* painter );
  314.  
  315. private:    // Disabled copy constructor and operator=
  316.     QPainter( const QPainter & );
  317.     QPainter &operator=( const QPainter & );
  318. };
  319.  
  320.  
  321. /*****************************************************************************
  322.   QPainter member functions
  323.  *****************************************************************************/
  324.  
  325. inline QPaintDevice *QPainter::device() const
  326. {
  327.     return pdev;
  328. }
  329.  
  330. inline bool QPainter::isActive() const
  331. {
  332.     return testf(IsActive);
  333. }
  334.  
  335. inline QFontMetrics QPainter::fontMetrics() const
  336. {
  337.     return QFontMetrics(this);
  338. }
  339.  
  340. inline QFontInfo QPainter::fontInfo() const
  341. {
  342.     return QFontInfo(this);
  343. }
  344.  
  345. inline const QFont &QPainter::font() const
  346. {
  347.     return cfont;
  348. }
  349.  
  350. inline const QPen &QPainter::pen() const
  351. {
  352.     return cpen;
  353. }
  354.  
  355. inline const QBrush &QPainter::brush() const
  356. {
  357.     return cbrush;
  358. }
  359.  
  360. /*
  361. inline PaintUnit QPainter::unit() const
  362. {
  363.     return (PaintUnit)pu;
  364. }
  365. */
  366.  
  367. inline const QColor &QPainter::backgroundColor() const
  368. {
  369.     return bg_col;
  370. }
  371.  
  372. inline BGMode QPainter::backgroundMode() const
  373. {
  374.     return (BGMode)bg_mode;
  375. }
  376.  
  377. inline RasterOp QPainter::rasterOp() const
  378. {
  379.     return (RasterOp)rop;
  380. }
  381.  
  382. inline const QPoint &QPainter::brushOrigin() const
  383. {
  384.     return bro;
  385. }
  386.  
  387. inline bool QPainter::hasViewXForm() const
  388. {
  389.     return testf(VxF);
  390. }
  391.  
  392. inline bool QPainter::hasWorldXForm() const
  393. {
  394.     return testf(WxF);
  395. }
  396.  
  397. inline bool QPainter::hasClipping() const
  398. {
  399.     return testf(ClipOn);
  400. }
  401.  
  402. inline const QRegion &QPainter::clipRegion() const
  403. {
  404.     return crgn;
  405. }
  406.  
  407. inline int QPainter::tabStops() const
  408. {
  409.     return tabstops;
  410. }
  411.  
  412. inline int *QPainter::tabArray() const
  413. {
  414.     return tabarray;
  415. }
  416.  
  417. inline HANDLE QPainter::handle() const
  418. {
  419. #if defined(_WS_WIN_)
  420.     return hdc;
  421. #elif defined(_WS_PM_)
  422.     return hps;
  423. #elif defined(_WS_X11_)
  424.     return hd;
  425. #endif
  426. }
  427.  
  428.  
  429. inline void QPainter::setBrushOrigin( const QPoint &p )
  430. {
  431.     setBrushOrigin( p.x(), p.y() );
  432. }
  433.  
  434. inline void QPainter::setWindow( const QRect &r )
  435. {
  436.     setWindow( r.x(), r.y(), r.width(), r.height() );
  437. }
  438.  
  439. inline void QPainter::setViewport( const QRect &r )
  440. {
  441.     setViewport( r.x(), r.y(), r.width(), r.height() );
  442. }
  443.  
  444. inline void QPainter::setClipRect( int x, int y, int w, int h )
  445. {
  446.     setClipRect( QRect(x,y,w,h) );
  447. }
  448.  
  449. inline void QPainter::drawPoint( const QPoint &p )
  450. {
  451.     drawPoint( p.x(), p.y() );
  452. }
  453.  
  454. inline void QPainter::moveTo( const QPoint &p )
  455. {
  456.     moveTo( p.x(), p.y() );
  457. }
  458.  
  459. inline void QPainter::lineTo( const QPoint &p )
  460. {
  461.     lineTo( p.x(), p.y() );
  462. }
  463.  
  464. inline void QPainter::drawLine( const QPoint &p1, const QPoint &p2 )
  465. {
  466.     drawLine( p1.x(), p1.y(), p2.x(), p2.y() );
  467. }
  468.  
  469. inline void QPainter::drawRect( const QRect &r )
  470. {
  471.     drawRect( r.x(), r.y(), r.width(), r.height() );
  472. }
  473.  
  474. inline void QPainter::drawWinFocusRect( const QRect &r )
  475. {
  476.     drawWinFocusRect( r.x(), r.y(), r.width(), r.height() );
  477. }
  478.  
  479. inline void QPainter::drawWinFocusRect( const QRect &r,const QColor &penColor )
  480. {
  481.     drawWinFocusRect( r.x(), r.y(), r.width(), r.height(), penColor );
  482. }
  483.  
  484. inline void QPainter::drawRoundRect( const QRect &r, int xRnd, int yRnd )
  485. {
  486.     drawRoundRect( r.x(), r.y(), r.width(), r.height(), xRnd, yRnd );
  487. }
  488.  
  489. inline void QPainter::drawEllipse( const QRect &r )
  490. {
  491.     drawEllipse( r.x(), r.y(), r.width(), r.height() );
  492. }
  493.  
  494. inline void QPainter::drawArc( const QRect &r, int a, int alen )
  495. {
  496.     drawArc( r.x(), r.y(), r.width(), r.height(), a, alen );
  497. }
  498.  
  499. inline void QPainter::drawPie( const QRect &r, int a, int alen )
  500. {
  501.     drawPie( r.x(), r.y(), r.width(), r.height(), a, alen );
  502. }
  503.  
  504. inline void QPainter::drawChord( const QRect &r, int a, int alen )
  505. {
  506.     drawChord( r.x(), r.y(), r.width(), r.height(), a, alen );
  507. }
  508.  
  509. inline void QPainter::drawPixmap( const QPoint &p, const QPixmap &pm,
  510.                   const QRect &sr )
  511. {
  512.     drawPixmap( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() );
  513. }
  514.  
  515. inline void QPainter::drawImage( const QPoint &p, const QImage &pm,
  516.                  const QRect &sr )
  517. {
  518.     drawImage( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() );
  519. }
  520.  
  521. inline void QPainter::drawTiledPixmap( const QRect &r, const QPixmap &pm,
  522.                        const QPoint &sp )
  523. {
  524.     drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, sp.x(), sp.y() );
  525. }
  526.  
  527. inline void QPainter::drawTiledPixmap( const QRect &r, const QPixmap &pm )
  528. {
  529.     drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, 0, 0 );
  530. }
  531.  
  532. inline void QPainter::fillRect( const QRect &r, const QBrush &brush )
  533. {
  534.     fillRect( r.x(), r.y(), r.width(), r.height(), brush );
  535. }
  536.  
  537. inline void QPainter::eraseRect( int x, int y, int w, int h )
  538. {
  539.     fillRect( x, y, w, h, backgroundColor() );
  540. }
  541.  
  542. inline void QPainter::eraseRect( const QRect &r )
  543. {
  544.     fillRect( r.x(), r.y(), r.width(), r.height(), backgroundColor() );
  545. }
  546.  
  547. inline void QPainter::drawText( const QPoint &p, const char *s, int len )
  548. {
  549.     drawText( p.x(), p.y(), s, len );
  550. }
  551.  
  552. inline void QPainter::drawText( const QRect &r, int tf,
  553.                 const char *str, int len, QRect *br, char **i )
  554. {
  555.     drawText( r.x(), r.y(), r.width(), r.height(), tf, str, len, br, i );
  556. }
  557.  
  558. inline QRect QPainter::boundingRect( const QRect &r, int tf,
  559.                      const char *str, int len, char **i )
  560. {
  561.     return boundingRect( r.x(), r.y(), r.width(), r.height(), tf, str, len,
  562.              i );
  563. }
  564.  
  565.  
  566. #endif // QPAINTER_H
  567.